Type TWall
	Field meshHead=0
	Field meshBack=0
	Field meshLeft=0
	Field meshRight=0
	
	Field bodyHead=0
	Field bodyBack=0
	Field bodyLeft=0
	Field bodyRight=0
	
End Type 


Function TWall_Create( p_ParentMesh, p_bShowHeadWall=False, p_bShowRightWall=False, p_bShowBackWall=False, p_bShowLeftWall=False )
	Local l_fFloorSize#=kTILE_SIZE#
	Local l_fHeight#=3
	Local l_fDepth#=1.0
	
	Local l_w.TWall = New TWall
	
	l_w\meshHead = 0 :	l_w\bodyHead = 0
	l_w\meshBack = 0 :	l_w\bodyBack = 0
	l_w\meshLeft = 0 :	l_w\bodyLeft = 0
	l_w\meshRight = 0 :	l_w\bodyRight = 0
	
	
	If p_bShowHeadWall And ( p_bShowLeftWall=False And p_bShowRightWall=False )
		l_w\meshHead = uCreateBox( l_fFloorSize#, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshHead,0,(l_fHeight/2),(l_fFloorSize#/2)-(l_fDepth#/2)
	ElseIf p_bShowHeadWall And p_bShowLeftWall And p_bShowRightWall = False 
		l_w\meshHead = uCreateBox( l_fFloorSize#-.9, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshHead,1,(l_fHeight/2),(l_fFloorSize#/2)-(l_fDepth#/2)
	ElseIf p_bShowHeadWall And p_bShowLeftWall=False And p_bShowRightWall = True 
		l_w\meshHead = uCreateBox( l_fFloorSize#-.9, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshHead,-1,(l_fHeight/2),(l_fFloorSize#/2)-(l_fDepth#/2)
	EndIf 
	
	If p_bShowBackWall And ( p_bShowLeftWall=False And p_bShowRightWall=False )
		l_w\meshBack = uCreateBox( l_fFloorSize#, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshBack,0,(l_fHeight/2),(-l_fFloorSize#/2)+(l_fDepth#/2)
	ElseIf p_bShowBackWall And p_bShowLeftWall=True And p_bShowRightWall=False
		l_w\meshBack = uCreateBox( l_fFloorSize#-.9, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshBack,1,(l_fHeight/2),(-l_fFloorSize#/2)+(l_fDepth#/2)
	ElseIf p_bShowBackWall And p_bShowLeftWall=False And p_bShowRightWall=True
		l_w\meshBack = uCreateBox( l_fFloorSize#-.9, l_fHeight, 1, p_ParentMesh )
		MoveEntity l_w\meshBack,-1,(l_fHeight/2),(-l_fFloorSize#/2)+(l_fDepth#/2)
	EndIf 
	
	If p_bShowRightWall
		l_w\meshRight = uCreateBox( 1, l_fHeight, l_fFloorSize#, p_ParentMesh )
		MoveEntity l_w\meshRight,(l_fFloorSize#/2)-(l_fDepth#/2),(l_fHeight/2),0
	EndIf 
	
	If p_bShowLeftWall
		l_w\meshLeft = uCreateBox( 1, l_fHeight, l_fFloorSize#, p_ParentMesh )
		MoveEntity l_w\meshLeft,(-l_fFloorSize#/2)+(l_fDepth#/2),(l_fHeight/2),0
	EndIf 
	
	
	If l_w\meshHead > 0 Then 
		l_w\bodyHead = TWAll_SetNewton( l_w\meshHead, 9999999  )
		uCelShading( l_w\meshHead,0.3)
	EndIf 
	If l_w\meshBack > 0
		l_w\bodyBack = TWAll_SetNewton( l_w\meshBack, 9999999 )
		uCelShading( l_w\meshBack,0.3)
	EndIf 
	If l_w\meshLeft > 0
		l_w\bodyLeft = TWAll_SetNewton( l_w\meshLeft, 9999999 )
		uCelShading( l_w\meshLeft,0.3)
	EndIf 
	If l_w\meshRight > 0
		l_w\bodyRight = TWAll_SetNewton( l_w\meshRight, 9999999 )
		uCelShading( l_w\meshRight,0.3)
	EndIf 
	
End Function 	

Function TWAll_SetNewton( p_Mesh, p_fMass#=1000 )
	
	Local l_body= BodyCreateHull( p_Mesh, p_fMass#)
	
	Local l_PosX# = EntityX( p_Mesh, True )
	Local l_PosY# = EntityY( p_Mesh, True )
	Local l_PosZ# = EntityZ( p_Mesh, True )
	
	Local l_P# = EntityPitch( p_Mesh, True )
	Local l_Y# = EntityYaw( p_Mesh, True )
	Local l_R# = EntityRoll( p_Mesh, True )
	
	phBodySetPos( l_body,l_PosX#, l_PosY#, l_PosZ#);
	phBodySetRot( l_body, l_P#, l_Y#, l_R#)
	phBodySetEntity(l_body,p_Mesh)
	
	Return l_body 
End Function 


Function TWall_Delete( p_W.TWall )
	If p_W\bodyHead Then phBodyDestroy(p_W\bodyHead)
	If p_W\bodyBack Then phBodyDestroy(p_W\bodyBack)
	If p_W\bodyLeft Then phBodyDestroy(p_W\bodyLeft)
	If p_W\bodyRight Then phBodyDestroy(p_W\bodyRight)
	
	If p_W\meshHead Then FreeEntity p_W\meshHead
	If p_W\meshBack Then FreeEntity p_W\meshBack
	If p_W\meshRight Then FreeEntity p_W\meshRight
	If p_W\meshLeft Then FreeEntity p_W\meshLeft	
	Delete p_W
End Function 

Function TWall_DeleteAll()
	Local l_w.TWall
	For l_w = Each TWall
		TWall_Delete(l_w)
	Next 
End Function	
;~IDEal Editor Parameters:
;~C#Blitz3D